function getChemicalSearchUrl(freeSearchOp, matchingAllTerms, matchingSearchHash) {
    return "/addama-rest/dudley-sample/path/datasource/Chemical/search?" + freeSearchOp + matchingAllTerms +
           "&PROJECTION=chemicalName" +
           "&PROJECTION=location" +
           "&PROJECTION=reorderKey" +
           "&PROJECTION=alias" +
           "&PROJECTION=keyword" +
           "&PROJECTION=comments" +
           matchingSearchHash;
}

function getChemicalPagingColumns() {
    return [
        {
            name: 'indexNum',
            type: 'float'
        },
        {
            name: 'key'
        },
        {
            name: 'chemicalName'
        },
        {
            name: 'location'
        },
        {
            name: 'reorderKey'
        },
        {
            name: 'alias'
        },
        {
            name: 'keyword'
        },
        {
            name: 'comments'
        }
    ];

}

function translateChemicalResultToJson(jsonSearchArray) {
    var jsonObj = [];
    var chemKey = jsonSearchArray.name;
    jsonObj[0] = chemKey.substring(4, chemKey.length);
    jsonObj[1] = jsonSearchArray.name;
    jsonObj[2] = jsonSearchArray.chemicalName;
    jsonObj[3] = jsonSearchArray.location;
    jsonObj[4] = jsonSearchArray.reorderKey;
    jsonObj[5] = jsonSearchArray.alias;
    jsonObj[6] = jsonSearchArray.keyword;
    jsonObj[7] = jsonSearchArray.comments;
    return jsonObj;
}

function translateChemicalSolrToJson(jsonSearchArray) {
    var jsonObj = [];
    var chemKey = jsonSearchArray.chemKey;
    jsonObj[0] = chemKey.substring(4, chemKey.length);
    jsonObj[1] = jsonSearchArray.chemKey;
    jsonObj[2] = jsonSearchArray.chemName;
    jsonObj[3] = jsonSearchArray.chemLocation;
    jsonObj[4] = jsonSearchArray.chemReorder;
    jsonObj[5] = jsonSearchArray.chemAlias;
    jsonObj[6] = jsonSearchArray.chemKeywords;
    jsonObj[7] = jsonSearchArray.chemComments;
    return jsonObj;
}

function initChemicalJson(oligoHash) {
    oligoHash.chemicalName = undefined;
    oligoHash.location = undefined;
    oligoHash.reorderKey = undefined;

}

function getChemicalSearchOptionsArray() {
    return [
        ['all', 'All'],
        ['chemicalKey', 'chemicalKey'],
        ['chemicalName', 'chemicalName'],
        ['location', 'location'],
        ['reorderKey', 'reorderKey']
    ];
}

function getChemicalSearchColumnHeaders() {
    return  [
        {
            header: 'Index',
            width: 50,
            sortable: true,
            dataIndex: 'indexNum'
        },
        {
            id:'chemicalKey',
            header: 'ChemicalKey',
            minColumnWidth: 100,
            sortable: true,
            dataIndex: 'key'
        },
        {
            header: 'Name',
            width: 200,
            sortable: true,
            dataIndex: 'chemicalName'
        },
        {
            header: 'Location',
            width: 100,
            sortable: true,
            dataIndex: 'location'
        },
        {
            header: 'Re-Order Key',
            width: 250,
            sortable: true,
            dataIndex: 'reorderKey'
        },
        {
            header: 'Keyword',
            width: 100,
            sortable: true,
            dataIndex: 'keyword'
        }

    ];
}

function populateChemicalJson(oHash, g) {
    oHash.name = g.getSelectionModel().getSelected().data.key;
    oHash.chemicalName = g.getSelectionModel().getSelected().data.chemicalName;
    oHash.location = g.getSelectionModel().getSelected().data.location;
    oHash.reorderKey = g.getSelectionModel().getSelected().data.reorderKey;
    oHash.alias = g.getSelectionModel().getSelected().data.alias;
    oHash.keyword = g.getSelectionModel().getSelected().data.keyword;
    oHash.comments = g.getSelectionModel().getSelected().data.comments;
}

function validateCreateUpdateChemical() {
    /*
     if (Ext.getCmp("chemicalNameId").getValue() == null || Ext.getCmp("chemicalNameId").getValue() == "") {
     Ext.Msg.alert('Error', 'Chemical name is required.');
     return false;
     } else if (Ext.getCmp("chemicalLocationId").getValue() == null || Ext.getCmp("chemicalLocationId").getValue() == "") {
     Ext.Msg.alert('Error', 'Location is required.');
     return false;
     }
     */
    return true;
}

